import { DetailsPage } from './../details/details';
import { LoadingController } from 'ionic-angular/components/loading/loading-controller';
import { Storage } from '@ionic/storage';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { RestProvider } from '../../providers/rest/rest';
import { BaseUI } from '../../common/baseui';

/**
 * Generated class for the NotificationPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-notification',
  templateUrl: 'notification.html',
})
export class NotificationPage extends BaseUI {

  errorMessage: any
  notificationList: string[]

  constructor(public navCtrl: NavController,
    public storage: Storage,
    public rest: RestProvider,
    public loadCtrl: LoadingController,
    public navParams: NavParams) {
      super()
  }

  ionViewDidLoad() {
    this.storage.get('userId').then((val)=> {
      if(val!=null) {
        let loading = super.showLoading(this.loadCtrl, "加载中...")
        this.rest.getUserNotifications(val)
        .subscribe(
          n => {
           this.notificationList = n
           //View不能隐藏的错误
            loading.dismissAll()
          },
         error=> this.errorMessage = <any>error
        )
      }
    })
  }

  gotoDetails(questionId) {
    this.navCtrl.push(DetailsPage, {id: questionId})
  }
}
